package com.htrq.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.htrq.entity.Page;
import com.htrq.entity.User;

@Repository
public class UserDao extends BaseDaoImpl<User> {
	public List<User> getAlluser(User user, Page page) {
		String hql = "select new com.htrq.entity.User (u.userid,u.uname,u.relname,u.upwd,u.telphone,r.rname) from User u ,HRole r where r.rid=u.rolid";
		if (user.getUname() != null && user.getUname() != "") {
			hql += " and u.uname='" + user.getUname().trim() + "'";
		}
		Query query = getCurrentSession().createQuery(hql);
		query.setFirstResult(page.getStart());
		query.setMaxResults(page.getLimit());
		return query.list();
	}
	public void saveuser(User user) {
		add(user);
	}
	public Long getTotal() {
		return getCount("select count(*) from User");
	}
}
